package easy;

public class Solution_605 {

    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        int num = 0;
        int length = flowerbed.length;
        for (int i = 0; i < length; i++) {
            if (flowerbed[i] == 0) {
                if ((i - 1 < 0 || flowerbed[i - 1] == 0) && (i + 1 == length || flowerbed[i + 1] == 0)) {
                    flowerbed[i] = 1;
                    num++;
                }
            }
        }
        System.out.println(num);
        return n <= num;
    }

    public static void main(String[] args) {
        Solution_605 model = new Solution_605();
        System.out.println(model.canPlaceFlowers(new int[]{1,0,0,0,1}, 1));
        System.out.println(model.canPlaceFlowers(new int[]{1,0,0,0,1}, 2));
    }
}
